package com.qnvip.sbd.service.impl;

import com.qnvip.sbd.dao.AdminDao;
import com.qnvip.sbd.entity.Admin;
import com.qnvip.sbd.service.AdminService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Eric Lin
 *
 * 2017-10-19
 */
 @Service("adminService")
public class AdminServiceImpl implements AdminService {

	@Autowired
	private AdminDao adminDao;

	@Override
	public List<Admin> select(Admin condition, String targetColumns, String otherCondition) {
		return adminDao.select(condition, targetColumns, otherCondition);
	}

	@Override
	public Admin selectOne(Admin condition, String targetColumns, String otherCondition) {
		if (StringUtils.isEmpty(otherCondition)) {
			otherCondition = "limit 1";
		} else {
			otherCondition += " limit 1";
		}
		List<Admin> list = adminDao.select(condition, targetColumns, otherCondition);
		if (list == null || list.size() == 0)
			return null;
		return list.get(0);
	}
}
